let dragons = require('dragons');
var eventsMgr = require('eventsMgr');
var actions = require('actions');
var consts = require('consts');
var soundMgr = require('soundMgr');
cc.Class({
    extends: cc.Component,

    properties: {
        feiJi:cc.Node,
        oldy:0,
    },

    onLoad () {

    },

    start() {
        this._initNodeTouchEvent();
        var canvas = cc.find('Canvas');
        this.WordPosition = cc.find('Canvas');
    },
    _initNodeTouchEvent() {
        //监听事件
        this.node.on(cc.Node.EventType.TOUCH_START, this._onTouchBegin, this);
        this.node.on(cc.Node.EventType.TOUCH_MOVE, this._onTouchMoved, this);
        this.node.on(cc.Node.EventType.TOUCH_END, this._onTouchEnd, this);
        this.node.on(cc.Node.EventType.TOUCH_CANCEL, this._onTouchCancel, this);
    },

    _destroyTouchEvent() {
        //销毁事件
        this.node.off(cc.Node.EventType.TOUCH_START, this._onTouchBegin, this);
        this.node.off(cc.Node.EventType.TOUCH_MOVE, this._onTouchMoved, this);
        this.node.off(cc.Node.EventType.TOUCH_END, this._onTouchEnd, this);
        this.node.off(cc.Node.EventType.TOUCH_CANCEL, this._onTouchCancel, this);
    },


    _onTouchBegin: function (event) {
        var temp = event.getLocation();
        var location = this.WordPosition.convertToNodeSpaceAR(temp);
        // console.log(location);
        this.oldy = location.y;
    },

    _onTouchMoved: function (event) {
        // console.log('yidddddddddddddddddd')
        var temp = event.getLocation();
        var location = this.WordPosition.convertToNodeSpaceAR(temp);
        let juli = location.y - this.oldy;
        // console.log(juli);
        if(juli > 0){
            this.oldy = location.y;
            this.feiJi.y += juli;
        }else {
            this.oldy = location.y;
            this.feiJi.y += juli;
        }
    },

    _onTouchEnd: function (event) {
        this.oldx = 0;
        this.oldy = 0;
    },

    _onTouchCancel: function (event) {
        this.oldx = 0;
        this.oldy = 0;
    },

    onDestroy() {
        this._destroyTouchEvent();
    },

});